package com.ftg.learn.rbac.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ftg.learn.rbac.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author Guo
 * @date 2022/2/8
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 查某个人具有的角色
     * @param uid
     * @return
     */
    @Select("select rid from sys_user_role where uid = #{uid}")
    List<Map<String,Object>> showRoleForUserId(@Param("uid") Long uid);


    /**
     * 对操作的用户删除角色
     * @param uid
     * @return
     */
    @Delete("delete from sys_user_role where uid = #{uid}")
    int delRoleForUserId(@Param("uid") Long uid);


    /**
     * 对操作的用户添加新角色
     * @param rid
     * @param uid
     * @return
     */
    @Insert("insert into sys_user_role (rid,uid) values(#{rid},#{uid})")
    int saveRoleForUserId(@Param("rid") Long rid,@Param("uid") Long uid);


}
